// 刷固定机枪插件

string author = "Live";
string pluginName = "CreateMountedGun 刷固定机枪插件";
string version = "0.1";

int gamemode = 0;

// 插件初始化
void OnPluginInit()
{
	// 设置插件信息
	PluginData::SetAuthor(author);
	PluginData::SetName(pluginName);
	PluginData::SetVersion(version);

	// 提示
	ThePresident.InfoFeed("插件:"+pluginName+"| 版本:"+version+"| 作者:"+author,false);
	
	// 当玩家说
    Events::Player::PlayerSay.Hook( @PlayerSay );
    
}

// 当玩家say
HookReturnCode PlayerSay(CTerrorPlayer@ pPlayer, CASCommand@ pArgs)
{

	string arg = pArgs.Arg( 1 );
	string arg1 = "";
	string arg2 = "";

	// 切分字符串(这样就可以用空格传一个命令参数了)
	int subIndex = arg.findFirst(" ",0);
	if(not (subIndex < 0)){
		arg1 = arg.substr(0,subIndex);
		arg2 = arg.substr(subIndex+1,-1);
		//Chat.PrintToChat(all,""+arg1+"|"+arg2);
	}else{
		arg1 = arg;
	}
	
	if( arg1 == "!cpg" ){
		Vector v = pPlayer.GetAbsOrigin();
		QAngle qa = pPlayer.GetAbsAngles();
		CEntityData@ inputdata = EntityCreator::EntityData();
		// 经过实测 MaxPitch MinPitch 分别为最高角度/最低角度 其极限值为大约-60度~60度之间
		// MaxYaw 为最大左右旋转角度，其极限值大约为180度
		// 但是以下都设置为360度是因为当取消机枪碰撞模型时，按E很难触发，增大值能更容易触发
		inputdata.Add("MaxPitch","360.00");
		inputdata.Add("MinPitch","-360.00");
		inputdata.Add("MaxYaw","360.00");
		CBaseEntity@ mounted_gun = EntityCreator::Create("prop_mounted_machine_gun",v,qa,inputdata);
		mounted_gun.SetSolidType(SOLID_NONE);
		Chat.PrintToChat(pPlayer,"原地生成了一个固定机枪");
	}
	
	return HOOK_CONTINUE;

}